<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var rotate = function (matrix) {
        let m = matrix.length
        let n = matrix[0].length
        let top = 0
        let bottom = m - 1
        while (top < bottom) {
          ;[matrix[top], matrix[bottom]] = [matrix[bottom], matrix[top]]
          top++
          bottom--
        }
        for (let i = 0; i < m; i++) {
          for (let j = i; j < n; j++) {
            ;[matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]]
          }
        }
        return matrix
      }
    </script>
  </body>
</html>
